package com.enniu;

import java.net.URL;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.CharacterEncodingFilter;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;

/**
 * @author xingliangbo
 */
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

	// 编码过滤器
	@Bean
	Filter characterEncodingFilter() {
		CharacterEncodingFilter filter = new CharacterEncodingFilter();
		filter.setEncoding("UTF-8");
		filter.setForceEncoding(true);
		return filter;
	}

	@Bean
	public ServletRegistrationBean shallowEtagHeaderFilter() {
		ServletRegistrationBean registrationBean = new ServletRegistrationBean();
		registrationBean.setServlet(new StatViewServlet());
		registrationBean.setOrder(1);
		registrationBean.addUrlMappings("/druid/*");
		return registrationBean;
	}

	@Bean
	Filter druidWebStatFilter() {
		WebStatFilter filter = new WebStatFilter();
		return filter;
	}


	public static void main(String[] args) throws Exception {
		SpringApplication.run(Application.class, args);
	}

}